#include <iostream>
#include <vector>

int const maxn = 103;
int pos[maxn][maxn];
int n;

std::vector<std::vector<int> > ans;
std::vector<int> way;

void reduce(int start, int end, int x)
{
	for (int i = start; i < end; i += 2) {
		way.push_back(pos[x][i]); way.push_back(pos[i][x]);
	}
}

void decrease_bound(int len, int x, int move)
{
	if (len == 1) return;
	int y = x + len - 1;

	way.clear(); way.push_back(move);
	way.push_back(pos[x][x]); way.push_back(pos[x][y]);
	way.push_back(pos[y][x]); way.push_back(pos[y][y]);
	reduce(x+2, y, x); reduce(x+2, y, y);
	ans.push_back(way);

	way.clear(); way.push_back(move+2);
	reduce(x+1, y, x); reduce(x+1, y, y);
	ans.push_back(way);

	decrease_bound(len-2, x+1, move+4);
}

void shrink_to_odd(int len, int x, int move)
{
	int y = x + len - 1;
	way.clear(); way.push_back(move);
	way.push_back(pos[y][y]);
	ans.push_back(way);

	way.clear(); way.push_back(move+1);
	reduce(x+1, y, y);
	ans.push_back(way);

	way.clear(); way.push_back(move+3);
	reduce(x, y, y);
	ans.push_back(way);

	decrease_bound(len-1, x, move+5);
}

int main()
{
	std::cin >> n;
	if (n == 2) { std::cout << "2 2\n3 1 4\n"; return 0; }
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) pos[i][j] = (i-1)*n + j;
	if (!(n&1)) shrink_to_odd(n, 1, n);
	else        decrease_bound(n, 1, n);

	for (int i = 0; i < int(ans.size()); i++) {
		std::cout << ans[i][0];
		for (int j = 1; j < int(ans[i].size()); j++)
			std::cout << " " << ans[i][j];
		std::cout << "\n";
	}
}

